local _, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local Prefix = ZL.Prefix
local tableSort = ZL.tableSort
local autoBid = ZL.autoBid
local GameTooltipShow = ZL.GameTooltipShow
local GetStartAndIncrementBid = ZL.GetStartAndIncrementBid
local GetCurrentRoster = ZL.GetCurrentRoster

local cGetItemInfo, cGetItemIcon
if WOW_PROJECT_ID == 1 then
    cGetItemInfo = C_Item.GetItemInfo
    cGetItemIcon = C_Item.GetItemIconByID
else --WOW_PROJECT_ID == 11 then
    cGetItemInfo = GetItemInfo
    cGetItemIcon = GetItemIcon
end


--定义静态弹出对话框
--重置当前拍卖记录
StaticPopupDialogs["ZL_RESETCURRENT"] = {
	text = "%s\n\n请为当前拍卖记录输入一个名字\n(不输入将使用当前名字：|cffffd100%s|r)：",
	button1 = "重置",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    -- EditBoxOnTextChanged = function(self)
	-- 	if strlen(self:GetText()) > 0 then
	-- 		self:GetParent().button1:Enable()
	-- 	else
	-- 		self:GetParent().button1:Disable()
	-- 	end
	-- end,
    OnShow = function(self)
		-- self.button1:Disable()
        self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		if (next(ZL_CURRENT, nil)) then
            for _, f in ipairs(ZL.AuctionFrame.entries) do f:Hide() end
            local totalincome = 0
            if ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                for _, fdata in ipairs(ZL_CURRENT.IncomeList) do
                    totalincome = totalincome + fdata.amount
                end
            end
            ZL_CURRENT.totalincome = totalincome
            ZL_CURRENT.name = strlen(self.editBox:GetText()) > 0 and self.editBox:GetText() or ZL_CURRENT.name
			table.insert(ZL_HISTORY, ZL_CURRENT)
            ZL_CURRENT = {}
            ZL.AuctionFrame:Update()
            ZL.AuctionRecordFrame.historyFrame:Update()
            ZL.AuctionRecordFrame.currentIncomeFrame:Update()
            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
		else
			print(Prefix("当前没有拍卖记录！"))
        end
        MyAddon:TransmitAddonInfo("AUTOAUC RESET", "重置")
        ZL.TransmitAddonInfo_Pro()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--重置当前拍卖记录警告
StaticPopupDialogs["ZL_RESETCURRENTWARNING"] = {
	text = "警告！警告！当前存在拍卖中的物品：%s个，请先取消所有拍卖中的物品后再重置！",
	button1 = "确定",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--进入全新副本时提醒是否重置拍卖记录
StaticPopupDialogs["ZL_RESETCURRENTINFO"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        ZL.AuctionFrame.reset:Click()
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--手动添加收支记录
StaticPopupDialogs["ZL_ADDINCOME"] = {
    text = "【|cffffd100%s|r】请输入玩家名、收支金额、备注",
    button1 = "确定",
    button2 = "取消",
    -- hasEditBox2 = true, -- 玩家名字
	-- hasEditBox3 = true, -- 收支金额
    -- hasEditBox4 = true, -- 备注
    OnShow = function(self, data)
		self.button1:Disable()
        -- self.text:SetJustifyH("LEFT")
        local xSize = 130 --self.editBox:GetWidth()
        local ySize = 30 --self.editBox:GetHeight()
         if not self.editBox2 then
			self.editBox2 = CreateFrame("EditBox", "StaticPopupDialogsEditBox2", self, "InputBoxTemplate")
			self.editBox2:SetSize(xSize, ySize)
			self.editBox2:SetPoint("TOP", self.text, "BOTTOM", 10, -10)
			self.editBox2:SetAutoFocus(false)
			self.editBox2:SetMaxLetters(150)
			self.editBox2.text = self.editBox2:CreateFontString(nil, "OVERLAY")
			self.editBox2.text:SetFontObject(GameFontWhite)
			self.editBox2.text:SetPoint("RIGHT", self.editBox2, "LEFT", -15, 0)
			self.editBox2.text:SetText("玩家名：")
            self.editBox2.text2 = self.editBox2:CreateFontString(nil, "OVERLAY")
			self.editBox2.text2:SetFontObject(GameFontWhite)
			self.editBox2.text2:SetPoint("LEFT", self.editBox2, "RIGHT", 5, 0)
		end
        if not self.editBox3 then
			self.editBox3 = CreateFrame("EditBox", "StaticPopupDialogsEditBox3", self, "InputBoxTemplate")
			self.editBox3:SetSize(xSize, ySize)
			self.editBox3:SetPoint("TOP", self.editBox2, "BOTTOM", 0, 5)
			self.editBox3:SetAutoFocus(false)
			self.editBox3:SetMaxLetters(9)
            self.editBox3:SetNumeric(true)
            self.editBox3:SetScript("OnEnter", function (self)
                GameTooltip:ClearAllPoints()
                GameTooltip:ClearLines()
                GameTooltip:SetOwner(self, "ANCHOR_NONE")
                GameTooltip:AddLine("输入大于0的数，最大9个字符！")
                GameTooltip:SetPoint("LEFT", self, "RIGHT")
                GameTooltip:Show()
            end)
            self.editBox3:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
			self.editBox3.text = self.editBox3:CreateFontString(nil, "OVERLAY")
			self.editBox3.text:SetFontObject(GameFontWhite)
			self.editBox3.text:SetPoint("RIGHT", self.editBox3, "LEFT", -15, 0)
			self.editBox3.text:SetText("金　额：")
            self.editBox3.text2 = self.editBox3:CreateFontString(nil, "OVERLAY")
			self.editBox3.text2:SetFontObject(GameFontWhite)
			self.editBox3.text2:SetPoint("LEFT", self.editBox3, "RIGHT", 5, 0)
			self.editBox3.text2:SetText("(必填)")
		end
        if not self.editBox4 then
			self.editBox4 = CreateFrame("EditBox", "StaticPopupDialogsEditBox4", self, "InputBoxTemplate")
			self.editBox4:SetSize(xSize, ySize)
			self.editBox4:SetPoint("TOP", self.editBox3, "BOTTOM", 0, 5)
			self.editBox4:SetAutoFocus(false)
			self.editBox4:SetMaxLetters(150)
            self.editBox4:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
            self.editBox4:SetScript("OnMouseUp", function (self)
                if (select(1, GetCursorInfo())) == "item" then
                    self:SetText(select(3, GetCursorInfo()))
                    ClearCursor()
                end
            end)
			self.editBox4.text = self.editBox4:CreateFontString(nil, "OVERLAY")
			self.editBox4.text:SetFontObject(GameFontWhite)
			self.editBox4.text:SetPoint("RIGHT", self.editBox4, "LEFT", -15, 0)
			self.editBox4.text:SetText("备　注：")
            self.editBox4.text2 = self.editBox4:CreateFontString(nil, "OVERLAY")
			self.editBox4.text2:SetFontObject(GameFontWhite)
			self.editBox4.text2:SetPoint("LEFT", self.editBox4, "RIGHT", 5, 0)
			self.editBox4.text2:SetText("(必填)")
		end
        local function CreateMenu(self, level, menuList)
            local currentRoster = GetCurrentRoster()
            local info = UIDropDownMenu_CreateInfo()
            if (level or 1) == 1 then
                for i = 1, #currentRoster do
                    if #currentRoster[i] > 0 then
                        info.text = "小队 " .. i
                        info.hasArrow = true
                        info.menuList = currentRoster[i]
                        UIDropDownMenu_AddButton(info, level)
                    end
                end
            else
                for _, name in ipairs(menuList) do
                    info.text = name
                    info.hasArrow = false
                    info.func = function()
                        self:GetParent().editBox2:SetText(name)
                        info.checked = true
                        CloseDropDownMenus()
                    end
                    UIDropDownMenu_AddButton(info, level)
                end
            end
        end
        if not self.dropDown then
            self.dropDown = CreateFrame("FRAME", "WPDemoDropDown", self, "UIDropDownMenuTemplate")
            self.dropDown:SetPoint("RIGHT", self.editBox2, "RIGHT", 17, -1)
            UIDropDownMenu_SetWidth(self.dropDown, 8)
            UIDropDownMenu_Initialize(self.dropDown, CreateMenu)
        end
        self.dropDown:Show()
        self.editBox2:SetScript("OnTextChanged", function (self)
            if data == "收入" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox3:SetScript("OnTextChanged", function (self)
            if data == "收入" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox4:SetScript("OnTextChanged", function (self)
            if data == "收入" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox4:SetScript("OnEnter", function (self)
            GameTooltip:ClearAllPoints()
            GameTooltip:ClearLines()
            GameTooltip:SetOwner(self, "ANCHOR_NONE")
            if data == "收入" then
                GameTooltip:AddLine("如：罚款，垃圾或其他收入")
            elseif data == "支出" then
                GameTooltip:AddLine("如：补贴，物资消耗支出等")
            end
            GameTooltip:AddLine("|cffffd100提示：|r鼠标点击物品移动到这里可直接获取物品名称", 1, 1, 1)
            GameTooltip:SetPoint("LEFT", self, "RIGHT")
            GameTooltip:Show()
        end)
        self.editBox2:SetText("")
		self.editBox3:SetText("")
        self.editBox4:SetText("")
        self.editBox2:Show()
        self.editBox3:Show()
        self.editBox4:Show()
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
		self:SetHeight(85 + self.editBox2:GetHeight() + self.editBox3:GetHeight() + self.editBox4:GetHeight())
        do
            local editboxList = {"StaticPopupDialogsEditBox2", "StaticPopupDialogsEditBox3", "StaticPopupDialogsEditBox4"}
            local function OnTabPressed(self)
                EditBox_HandleTabbing(self, editboxList)
            end
            self.editBox2:SetScript("OnTabPressed", OnTabPressed)
            self.editBox3:SetScript("OnTabPressed", OnTabPressed)
            self.editBox4:SetScript("OnTabPressed", OnTabPressed)
        end
        if data == "收入" then
            self.editBox2.text2:SetText("(必填)")
        elseif data == "支出" then
            self.editBox2.text2:SetText("(可选)")
        end
    end,
    OnUpdate = function(self)
		-- 确保高度保持不变
		self:SetHeight(85 + self.editBox2:GetHeight() + self.editBox3:GetHeight() + self.editBox4:GetHeight())
	end,
    OnAccept = function (self, data)
        local amount = 0
        if data == "收入" then
            amount = self.editBox3:GetNumber()
        elseif data == "支出" then
            amount = -self.editBox3:GetNumber()
        end
        local fdata = {
            type = "添加收支",
            player = self.editBox2:GetText(),
            amount = amount,
            notes = self.editBox4:GetText(),
        }
        MyAddon:TransmitAddonInfo("AUTOAUC SYNC", fdata)
    end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--清除所有历史记录警告
StaticPopupDialogs["ZL_CLEARHISTORYWARNING"] = {
	text = "警告！警告！将清空所有历史拍卖记录，并且无法恢复！是否确定清空？",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        for _, f in ipairs(ZL.AuctionRecordFrame.historyFrame.entries) do
            f:Hide()
        end
        ZL_HISTORY = {}
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--自动出价
StaticPopupDialogs["ZL_AUTOBID"] = {
    text = "输入你想对%s的最大出价金额(g):",
	button1 = "开始",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(true)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		data.f.maxAutoBid = self.editBox:GetNumber() or 0
        if data.f.maxAutoBid > 0 then
            data.f.Frame1.autobidBtn:SetText("停止出价")
            data.f.Frame1.bidbox:Disable()
            data.f.Frame1.bidBtn:Disable()
            data.f.Frame1.lgnoreBtn:Disable()
            self.editBox:ClearFocus()
            autoBid(data.index, data.f.maxAutoBid)
        end
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--撤销指定玩家的出价
StaticPopupDialogs["ZL_REVOKEBID"] = {
    text = "输入你想撤销出价的玩家名字:",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if strlen(self:GetText()) > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local playerName = self.editBox:GetText()
        MyAddon:TransmitAddonInfo("AUTOAUC REVOKE", {itemId=data.itemId, itemindex=data.itemindex, playerName=playerName})
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--增加玩家收入金额
StaticPopupDialogs["ZL_ADDTOPLAYER"] = {
    text = "输入你想|cffffd100增加|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(true)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local addamount = self.editBox:GetNumber() or 0
        if (not ZL_CURRENT.playerBalance) then ZL_CURRENT.playerBalance = {} end
        ZL_CURRENT.playerBalance[data]["balance"] = (ZL_CURRENT.playerBalance[data]["balance"] or 0 )+ addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--扣除玩家收入金额
StaticPopupDialogs["ZL_REMFROMPLAYER"] = {
    text = "输入你想|cffffd100扣除|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(true)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local addamount = self.editBox:GetNumber() or 0
        if (not ZL_CURRENT.playerBalance) then ZL_CURRENT.playerBalance = {} end
        ZL_CURRENT.playerBalance[data]["balance"] = (ZL_CURRENT.playerBalance[data]["balance"] or 0) - addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--手动创建拍卖物品
StaticPopupDialogs["ZL_ADDAUCTIONITEM"] = {
    text = "请填写需要拍卖的物品ID和数量：",
    button1 = "确定",
    button2 = "取消",
    OnShow = function(self, data)
		self.button1:Disable()
        local xSize = 130 --self.editBox:GetWidth()
        local ySize = 30 --self.editBox:GetHeight()
         if not self.editBox5 then
			self.editBox5 = CreateFrame("EditBox", "StaticPopupDialogseditBox5", self, "InputBoxTemplate")
			self.editBox5:SetSize(xSize, ySize)
			self.editBox5:SetPoint("TOP", self.text, "BOTTOM", 10, -10)
			self.editBox5:SetAutoFocus(false)
            self.editBox5:SetNumeric(true)
            self.editBox5:SetScript("OnTextChanged", function (self)
                if self:GetParent().editBox5:GetNumber() > 0 and self:GetParent().editBox6:GetNumber() > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end)
            self.editBox5:SetScript("OnMouseUp", function (self)
                if (select(1, GetCursorInfo())) == "item" then
                    self:SetText(select(2, GetCursorInfo()))
                    ClearCursor()
                end
            end)
            self.editBox5:SetScript("OnEnter", function (self)
                GameTooltipShow(self, "LEFT", "RIGHT")
                GameTooltip:AddLine("提示")
                GameTooltip:AddLine("鼠标点击物品，移动到这里，\n释放鼠标后可以自动获取到物品ID", 1, 1, 1)
                GameTooltip:AddLine("注意")
                GameTooltip:AddLine("如是打包的物品填写一个物品ID即可", 1, 1, 1)
                GameTooltip:Show()
            end)
            self.editBox5:SetScript("OnLeave", function ()
                GameTooltip:Hide()
            end)
			self.editBox5.text = self.editBox5:CreateFontString(nil, "OVERLAY")
			self.editBox5.text:SetFontObject(GameFontWhite)
			self.editBox5.text:SetPoint("RIGHT", self.editBox5, "LEFT", -15, 0)
			self.editBox5.text:SetText("物品ID：")
            self.editBox5.text2 = self.editBox5:CreateFontString(nil, "OVERLAY")
			self.editBox5.text2:SetFontObject(GameFontWhite)
			self.editBox5.text2:SetPoint("LEFT", self.editBox5, "RIGHT", 5, 0)
            self.editBox5.text2:SetText("(必填)")
		end
        if not self.editBox6 then
			self.editBox6 = CreateFrame("EditBox", "StaticPopupDialogseditBox6", self, "InputBoxTemplate")
			self.editBox6:SetSize(xSize, ySize)
			self.editBox6:SetPoint("TOP", self.editBox5, "BOTTOM", 0, 5)
			self.editBox6:SetAutoFocus(false)
            self.editBox6:SetNumeric(true)
            self.editBox6:SetScript("OnTextChanged", function (self)
                if self:GetParent().editBox5:GetNumber() > 0 and self:GetParent().editBox6:GetNumber() > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end)
            self.editBox6:SetScript("OnEnter", function (self)
                GameTooltipShow(self, "LEFT", "RIGHT")
                GameTooltip:AddLine("注意")
                GameTooltip:AddLine("如是拍卖打包的物品，数量填|cffffd1001|r", 1, 1, 1)
                GameTooltip:Show()
            end)
            self.editBox6:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
			self.editBox6.text = self.editBox6:CreateFontString(nil, "OVERLAY")
			self.editBox6.text:SetFontObject(GameFontWhite)
			self.editBox6.text:SetPoint("RIGHT", self.editBox6, "LEFT", -15, 0)
			self.editBox6.text:SetText("数　量：")
            self.editBox6.text2 = self.editBox6:CreateFontString(nil, "OVERLAY")
			self.editBox6.text2:SetFontObject(GameFontWhite)
			self.editBox6.text2:SetPoint("LEFT", self.editBox6, "RIGHT", 5, 0)
			self.editBox6.text2:SetText("(必填)")
		end
        self.editBox5:SetText("")
		self.editBox6:SetText("")
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.dropDown then self.dropDown:Hide() end
        self.editBox5:Show()
        self.editBox6:Show()
		self:SetHeight(85 + self.editBox5:GetHeight() + self.editBox6:GetHeight() + self.editBox5:GetHeight())
        do
            local editboxList = {"StaticPopupDialogseditBox5", "StaticPopupDialogseditBox6"}
            local function OnTabPressed(self)
                EditBox_HandleTabbing(self, editboxList)
            end
            self.editBox5:SetScript("OnTabPressed", OnTabPressed)
            self.editBox6:SetScript("OnTabPressed", OnTabPressed)
        end
    end,
    OnUpdate = function(self)
		-- 确保高度保持不变
		self:SetHeight(85 + self.editBox5:GetHeight() + self.editBox6:GetHeight() + self.editBox5:GetHeight())
	end,
    OnAccept = function (self, data)
        local itemId = self.editBox5:GetNumber()
        local itemCount = self.editBox6:GetNumber()
        if cGetItemIcon(itemId) ~= 134400 then
            local index = nil
            if ZL_CURRENT.auctionlist and (#ZL_CURRENT.auctionlist > 0) then
                for num, fdata in ipairs(ZL_CURRENT.auctionlist) do
                    if (fdata.itemId == itemId) then
                        index = num
                        break
                    end
                end
            end
            if index then
                print(Prefix("已存在拍卖记录！无法创建！"))
            else
                local startbidamount, bidIncrement = GetStartAndIncrementBid(itemId)
                local fdata = {
                    ["type"] = "创建拍卖",
                    ["itemId"] = itemId,
                    ["itemlink"] = select(2,cGetItemInfo(itemId)),
                    ["itemindex"] = 1,
                    ["startbidamount"] = startbidamount,
                    ["bidIncrement"] = bidIncrement,
                    ["state"] = "waiting",
                    ["lgnore"] = false,
                    ["countdownremaining"] = 0, --可以不用赋值，在启动拍卖的时候已经默认为ZL.opt.auctionTimer
                    ["isPaused"] = false,
                    ["bidderlist"] = {},
                    ["itemCount"] = itemCount,
                }
                MyAddon:TransmitAddonInfo("AUTOAUC SYNC", fdata)
            end
        else
            print(Prefix("未查询到该物品ID的信息，请核实填写是否正确！"))
        end
    end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}